// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from 'axios'
import ElementUI from 'element-ui'
import './../node_modules/element-ui/lib/theme-chalk/index.css'
import Vuex from 'vuex'
import VueCookie from 'vue-cookie'
import $ from 'jquery'
import App from './app'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import createRouter from './router/router'
import createStore from './store/store'
import * as socketApi from './assets/util/socket'
import elCascaderMulti from "el-cascader-multi";

Vue.use(VueRouter)
Vue.use(ElementUI)
Vue.use(Vuex)
Vue.use(VueCookie)
Vue.use(VueAwesomeSwiper)
Vue.use(elCascaderMulti)


Vue.prototype.$http = axios
Vue.prototype.socketApi = socketApi

const router = createRouter()
const store = createStore()
let roleId
if (JSON.parse(window.localStorage.getItem('access-user')) != null) {
    roleId = JSON.parse(window.localStorage.getItem('access-user')).roleId
}
// console.log(window.sessionStorage)
router.beforeEach((to, from, next) => {
    if(to.meta.requireAuth){
        if (JSON.parse(window.localStorage.getItem('access-user'))) {
            window.document.title = to.meta.title;
            next()
        }else{
            window.document.title = to.meta.title;
            next({
                path : '/login'
            })
        }
    }else {
        window.document.title = to.meta.title
        // if (roleId == 1) {
        //     next('/student/index')
        // } else if (roleId == 2){
        //     next('/teacher/index')
        // } else if (roleId == 3 || roleId == 4) {
        //     next('/admin/teacherMgt')
        // }else{
        //     next()
        // }
        next()
    }
    // router.options.routes[2].meta.title = JSON.parse(window.localStorage.getItem('loginData')).loginSystemName + ' - 登录'
    // self.$router.options.routes[2].meta.title = res.data.loginSystemName + ' - 登录'
    // console.log(self.$router.options.routes[2].meta.title)
    // window.document.title = to.meta.title;
    // next()
})

// Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
